﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;
using System.Collections;
using System.Runtime.InteropServices;

using SuperMapLib;

namespace JR_RouteAlarm
{
    class Utility
    {
        /*定数*/
        public const string ROUTE_FIELD = "SmUserId";
        public const float BUFFER_ALARM_DISTANCE = 1.1F;
        public const int BUFFER_ALARM_SMOOTH = 20;
        public const string BUFFER_TITLE = "バッファ";
        public static string datasourceAlias = string.Empty;

        /*変数*/
        public soDataSource objSource = null;
        private AxSuperMapLib.AxSuperWorkspace superWksp = null;
        private string SDBPath = String.Empty;
        public static Hashtable routeFtWithLn = null;

        public Utility(AxSuperMapLib.AxSuperWorkspace superWksp, string SDBPath)
        {
            this.superWksp = superWksp;
            this.SDBPath = SDBPath;
            InitializeSource();
            SetDatasetInfo();
        }

        private void InitializeSource()
        {
            //if (superWksp.Datasources[datasourceAlias] != null)
            //{
            //    superWksp.Datasources.Remove(datasourceAlias);
            //}

            objSource = superWksp.OpenDataSource(
                SDBPath, datasourceAlias, seEngineType.sceSDBPlus, false);
            if (objSource == null)
            {
                MessageBox.Show("initialize datasource fail");
            }
            else
            {
                //
            }
        }

        private void SetDatasetInfo()
        {
            routeFtWithLn = new Hashtable();
        }

        public void ReleaseMemory()
        {
            Marshal.ReleaseComObject(objSource);
            objSource = null;

            MessageBox.Show("Release memory OK!");
        }
    }
}
